package com.traffic.controller;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.traffic.annotation.ApiJsonObject;
import com.traffic.annotation.ApiJsonProperty;
import com.traffic.constant.Status;

import com.traffic.entity.Drivedata;
import com.traffic.entity.Rank;
import com.traffic.exception.BaseException;
import com.traffic.model.ApiResponse;
import com.traffic.service.DrivedataService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Api(tags = "每一段轨迹数据相关接口")
@RestController
@RequestMapping(value = "/drivedata")
@Slf4j
public class DrivedataController {

    @Autowired
    private DrivedataService drivedataService;

    @ApiOperation(value = "【轨迹驾驶数据】", notes = "查看")
    @ApiImplicitParam(paramType = "path", dataType = "Integer", name = "trailId", value = "轨迹id", required = true)
    @GetMapping("/look/{trailId}")
    public ApiResponse lookDrivedata(@PathVariable Long trailId) {

        QueryWrapper<Drivedata> wrapper = new QueryWrapper<>();
        Drivedata ddata = drivedataService.getOne(wrapper.eq("trail_id",trailId));

        return ApiResponse.ofStatus(Status.OK,ddata);
    }

    @ApiOperation(value = "【轨迹驾驶数据】", notes = "插入驾驶数据")
    @PostMapping("/insert")
    @ApiJsonObject(name = "Param",value = {
            @ApiJsonProperty(type =Integer.class,key = "trail_id",example = "1" , description = "轨迹id"),
            @ApiJsonProperty(type =Double.class,key = "score",example = "33.333" , description = "得分"),
            @ApiJsonProperty(type =Double.class,key = "average_speed",example = "56.83" , description = "平均速度"),
            @ApiJsonProperty(type =Double.class,key = "max_speed",example = "80.6" , description = "最大速度"),
            @ApiJsonProperty(type =Double.class,key = "average_acceleration",example = "2.5" , description = "平均加速度"),
            @ApiJsonProperty(type =Double.class,key = "max_acceleration",example = "3.6" , description = "最大加速度"),
            @ApiJsonProperty(type =Double.class,key = "mileage",example = "10.5" , description = "该轨迹里程"),
            @ApiJsonProperty(type =Double.class,key = "time",example = "12350" , description = "该段轨迹时间"),
            @ApiJsonProperty(type =Double.class,key = "stationarity",example = "3.665" , description = "平顺度"),
    })
    public ApiResponse insertDrivedata(@RequestBody Map<String, Object> Param) {


        int did = drivedataService.insertDriveData(Param);

        return ApiResponse.ofStatus(Status.OK,did);
    }

    @ApiOperation(value = "【轨迹驾驶数据】", notes = "更新驾驶数据")
    @PostMapping("/update")
    @ApiJsonObject(name = "Param",value = {
            @ApiJsonProperty(type =Integer.class,key = "id",example = "1" , description = "行驶数据id"),
            @ApiJsonProperty(type =Integer.class,key = "trail_id",example = "1" , description = "轨迹id"),
            @ApiJsonProperty(type =Double.class,key = "score",example = "33.333" , description = "得分"),
            @ApiJsonProperty(type =Double.class,key = "average_speed",example = "56.83" , description = "平均速度"),
            @ApiJsonProperty(type =Double.class,key = "max_speed",example = "80.6" , description = "最大速度"),
            @ApiJsonProperty(type =Double.class,key = "average_acceleration",example = "2.5" , description = "平均加速度"),
            @ApiJsonProperty(type =Double.class,key = "max_acceleration",example = "3.6" , description = "最大加速度"),
            @ApiJsonProperty(type =Double.class,key = "mileage",example = "10.5" , description = "该轨迹里程"),
            @ApiJsonProperty(type =Double.class,key = "time",example = "12350" , description = "该段轨迹时间"),
            @ApiJsonProperty(type =Double.class,key = "stationarity",example = "3.665" , description = "平顺度"),
    })
    public ApiResponse updateDrivedata(@RequestBody Map<String, Object> Param) {

        drivedataService.updateDriveData(Param);

        return ApiResponse.ofStatus(Status.OK);
    }






}
